package com.edu.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.commonutils.R;
import com.edu.eduservice.domain.EduCourse;
import com.edu.eduservice.domain.EduTeacher;
import com.edu.eduservice.service.EduCourseService;
import com.edu.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName IndexTeacherController
 * @date 2022/9/23 16:34
 * @Version 1.0
 */
//@CrossOrigin
@RestController
@Api(description = "讲师管理前端")
@RequestMapping("/eduservice/teacherfront")
public class IndexTeacherController {

    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduTeacherService eduTeacherService;

    @ApiOperation("讲师分页列表")
    @PostMapping("/front/page/{current}/{limit}")
    @ResponseBody
    public R getPage(@PathVariable Integer current,@PathVariable Integer limit){
        //设置分页条件
        Page<EduTeacher> page=new Page<>(current,limit);
        //把所有的数据存到map
      Map<String, Object> map =eduTeacherService.frontgetPage(page);
            //返回
        return  R.ok().data(map);
    }

    @ApiOperation("根据讲师id获取课程列表")
    @GetMapping("/byid/{id}")
    @ResponseBody
    public R getByid(@PathVariable String id){

        //查询讲师信息
        EduTeacher eduTeacher=eduTeacherService.getById(id);
        //按更新时间降序排列
     List<EduCourse> courses=eduCourseService.selectbyTeacher(id);


        return R.ok().data("teacher",eduTeacher).data("courses",courses);
    }

}
